from selenium.webdriver.common.by import By
from selenium import webdriver
import time
import pytest
import json
@pytest.fixture(scope='session')
def driver():
    driver=webdriver.Edge()
    driver.get('https://www.jiuxian.com/')
    driver.maximize_window()
    yield driver
    driver.quit()
def send_json(file):
    with open(file,'r',encoding='utf8') as f:
        data=json.load(f)
    return ([i['username'],i['password']]for i in data)
@pytest.mark.parametrize('username,password',send_json('hj.json'))
def test_jiuxian(driver,username,password):
    # 点击请登录
    driver.find_element(By.XPATH,'/html/body/div[2]/div/div[1]/div/a[1]').click()
    time.sleep(2)
    # 断言账号登录
    dy1=driver.find_element(By.XPATH,'//*[@id="loginform"]/div/div/div/div/div[1]/div[1]/a[1]').text
    print(dy1)
    time.sleep(2)
    # 输入用户名和密码
    driver.find_element(By.NAME,'uname').send_keys(username)
    driver.find_element(By.NAME,'_pwd').send_keys(password)
    time.sleep(10)
    # 点击登录
    driver.find_element(By.ID,'save').click()
    time.sleep(2)
    # # 点击确定
    # driver.find_element(By.CSS_SELECTOR,'.bindSub').click()
    # time.sleep(2)